package com.yanqingying.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yanqingying.GetStudent;
import com.yanqingying.PageBean;
import com.yanqingying.Student;
import com.yanqingying.StudentQueryParam;
import com.yanqingying.mapper.StudentMapper;
import com.yanqingying.service.StudentService;
import com.yanqingying.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    StudentMapper studentMapper;

    public PageBean getPage(StudentQueryParam studentQueryParam) {
        PageHelper.startPage(studentQueryParam.getPage(), studentQueryParam.getPageSize());
        Page<Student> students = studentMapper.list(studentQueryParam);
        return new PageBean(students.getTotal(),students.getResult());
    }

    @Override
    public void deletes(List<Integer> ids) {
        studentMapper.deletes(ids);
    }

    @Override
    public void add(Student student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.add(student);
    }

    @Override
    public GetStudent gate(Integer id) {
        return studentMapper.gate(id);
    }

    @Override
    public void upDate(GetStudent student) {
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.upDate(student);
    }

    @Override
    public void violation(Integer id, Integer score) {
        studentMapper.violation(id, score);
    }

}
